/**
 *
 */
package jp.seraph.same.view.cui;

import jp.seraph.cui.AbstractMode;
import jp.seraph.cui.InternalConsole;
import jp.seraph.cui.Mode;
import jp.seraph.cui.SystemNodeType;
import jp.seraph.jsade.model.JointIdentifierContainer;
import jp.seraph.same.controller.DefaultMotionElementController;
import jp.seraph.same.controller.MotionElementController;
import jp.seraph.same.controller.MotionSessionController;
import jp.seraph.same.model.MotionElementModel;
import jp.seraph.same.model.MotionSessionModel;

/**
 *
 *
 */
public class MotionSessionData extends AbstractMode {

    /**
     * @param aParent
     * @param aConsole
     */
    public MotionSessionData(Mode aParent, InternalConsole aConsole, Integer aNumber, MotionSessionModel aModel, MotionSessionController aController, JointIdentifierContainer aIdContainer) {
        super(aParent, aConsole);

        mNumber = aNumber;
        mModel = aModel;
        mController = aController;
        mIdContainer = aIdContainer;
    }

    private Integer mNumber;
    private MotionSessionModel mModel;
    private MotionSessionController mController;
    private JointIdentifierContainer mIdContainer;

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return mNumber.toString();
    }

    public int getNumber(){
        return mNumber.intValue();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return MotionSessionDataType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#setName(java.lang.String)
     */
    public void setName(String aName) {
        try{
            Integer tNumber = Integer.getInteger(aName);
            mNumber = tNumber;
        }catch(NumberFormatException e){
            throw new IllegalArgumentException(e);
        }
    }

    public MotionSessionModel getSession(){
        return mModel;
    }

    @Override
    public void delete() {
        super.delete();
        mController.delete();
    }

    public void addElement(String aElementName){
        MotionElementModel tModel = mController.createElement(aElementName);
        MotionElementController tController = new DefaultMotionElementController(tModel, mController, mIdContainer);
        MotionElementData tNewData = new MotionElementData(this, this.getConsole(), aElementName, tController, tModel);

        this.addChild(tNewData);
    }
}
